let quickWebAxiosInstance = AxiosUtil.createAxiosInstance(axios);

//服务端功能提供
const quickWebJs = {
    saveKeyValue: function (key, value, callback, finallCallback) {
        let realValue = value;
        if (typeof value == "object" || value instanceof Array) {
            realValue = JsonUtil.stringify(value)
        }
        quickWebAxiosInstance.post(`/quickwebjs/sqllite/saveKey`, {
            key: key,
            value: realValue,
        }).then(response => {
            if (callback) {
                callback(response, null)
            }
        }).catch(error => {
            if (callback) {
                callback(null, error)
            }
        }).finally(function () {
            if (finallCallback) {
                finallCallback();
            }
        });
    },
    getKeyValue: function (key, callback) {
        quickWebAxiosInstance.get(`/quickwebjs/sqllite/getKey`, {
            params: {
                key: key,
            }
        }).then(response => {
            if (callback) {
                callback(response, null)
            }
        }).catch(error => {
            if (callback) {
                callback(null, error)
            }
        });
    },
    uploadEasyFile: function (file, type, callback) {
        quickWebAxiosInstance.post(`/quickwebjs/easyfile/upload`, {
            file: file,
            type: type
        },{
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }).then(response => {
            if (callback) {
                callback(response, null)
            }
        }).catch(error => {
            if (callback) {
                callback(null, error)
            }
        });
    },
    /**
     * url = http://ip:port/static/easyfile/{type}/{fileName}
     * @param typeAndFileName  '{type}/{fileName}'
     */
    getEasyFileUrl: function (typeAndFileName) {
        return window.location.origin + "/static/easyfile/" + typeAndFileName;
    }
};